package com.anpy.security.dto;

import com.anpy.security.entity.TRole;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

/**
 * u89d2u8272u6570u636eu4f20u8f93u5bf9u8c61
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class TRoleDTO {

    private Integer id;

    @NotBlank(message = "u89d2u8272u540du79f0u4e0du80fdu4e3au7a7a")
    @Size(min = 2, max = 50, message = "u89d2u8272u540du79f0u957fu5ea6u5e94u4e3a2-50u4e2au5b57u7b26")
    private String name;

    @Size(max = 255, message = "u63cfu8ff0u4fe1u606fu4e0du80fdu8d85u8fc7255u4e2au5b57u7b26")
    private String description;

    private Boolean status;

    private LocalDateTime createdAt;

    /**
     * u5c06DTOu8f6cu6362u4e3au5b9eu4f53u5bf9u8c61
     *
     * @return u89d2u8272u5b9eu4f53u5bf9u8c61
     */
    public TRole toEntity() {
        TRole role = new TRole();
        role.setId(this.id);
        role.setName(this.name);
        role.setDescription(this.description);
        role.setStatus(this.status);
        role.setCreatedAt(this.createdAt);
        return role;
    }

    /**
     * u5c06u5b9eu4f53u5bf9u8c61u8f6cu6362u4e3aDTO
     *
     * @param role u89d2u8272u5b9eu4f53u5bf9u8c61
     * @return u89d2u8272DTOu5bf9u8c61
     */
    public static TRoleDTO fromEntity(TRole role) {
        TRoleDTO dto = new TRoleDTO();
        dto.setId(role.getId());
        dto.setName(role.getName());
        dto.setDescription(role.getDescription());
        dto.setStatus(role.getStatus());
        dto.setCreatedAt(role.getCreatedAt());
        return dto;
    }
}
